package com.freewater.library.lending.book.presentation;

import com.freewater.library.lending.book.application.BookInstanceCommandService;
import com.freewater.library.lending.book.presentation.request.*;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@Slf4j
@RestController
@RequestMapping("/book-instance")
@RequiredArgsConstructor
@Validated
public class BookInstanceController {

    private final BookInstanceCommandService bookInstanceCommandService;

    @PostMapping("/create-book")
    public void createBook(@Validated @RequestBody CreateBookInstanceRequest request) {
        this.bookInstanceCommandService.createBook(request.toCommand());
    }

    @PostMapping("put-on")
    public void putOn(@Validated @RequestBody PutOnBookInstanceRequest request) {
        this.bookInstanceCommandService.putOnBook(request.toCommand());
    }

    @PostMapping("/take-off")
    public void takeOff(@Validated @RequestBody TakenOffBookInstanceRequest request) {
        this.bookInstanceCommandService.takenOffBook(request.toCommand());
    }

    @PostMapping("/reserve")
    public void reserve(@Validated @RequestBody ReserveBookInstanceRequest request) {
        this.bookInstanceCommandService.reserveBook(request.toCommand());
    }

    @PostMapping("/cancel-reserve")
    public void cancelReserve(@Validated @RequestBody CancelReserveBookInstanceRequest request) {
        this.bookInstanceCommandService.cancelReserveBook(request.toCommand());
    }

    @PostMapping("/check-out")
    public void checkOut(@Validated @RequestBody CheckOutBookInstanceRequest request) {
        this.bookInstanceCommandService.checkOutBook(request.toCommand());
    }

    @PostMapping("/submit-lost")
    public void submitLost(@Validated @RequestBody CheckOutBookInstanceLostRequest request) {
        this.bookInstanceCommandService.checkOutBookLost(request.toCommand());
    }

    @PostMapping("return-back")
    public void returnBack(@Validated @RequestBody ReturnBackBookInstanceRequest request) {
        this.bookInstanceCommandService.returnBackBook(request.toCommand());
    }
}
